// 防抖函数
import initApi from '@/apis/init.js';
export function debounce(fn, delay) {
	let timer
	return function() {
		if (timer) {
			clearTimeout(timer)
		}
		timer = setTimeout(() => {
			fn()
		}, delay)
	}
}

export function customDebounce(func, delay) {
	let timer = null;
	let isFirstClick = true;
	return function() {
		if (isFirstClick) {
			func.apply(this, arguments);
			isFirstClick = false;
		} else {
			clearTimeout(timer);
			timer = setTimeout(() => {
				func.apply(this, arguments);
			}, delay);
		}
	};
}
export function test() {
	console.log('----->>>>');
	my.openEmbeddedMiniProgram({
		appId: '2021004129621025',
		path: 'pages/keep_tcqv3_hf/keep_tcqv3_hf?a=123aaa',
		success: (res) => {
			console.log(res); // {success: true}
		},
		fail: (err) => {
			console.log(err);
		}
	});
};

// 统计
export function getProductNum(a, p, uuids) {
	if (a && p && uuids) {
		const arr = {
			channelCode: a,
			productCode: p,
			uuid: uuids
		};
		initApi.indicatorsRecordPageViewsPost(arr);
	}
}